package com.qgs.waf.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.qgs.waf.mapper.CustomerMapper;
import com.qgs.waf.mapper.DeviceMapper;
import com.qgs.waf.mapper.IndustryMapper;
import com.qgs.waf.mapper.ProvinceMapper;
import com.qgs.waf.model.Device;
import com.qgs.waf.model.Industry;
import com.qgs.waf.model.Province;
import com.qgs.waf.service.ZbksAttackSummaryService;
import com.qgs.waf.util.JSonUtil;
import com.qgs.waf.util.StringUtil;

@Service(value = "zbksAttackSummaryServiceImpl")
public class ZbksAttackSummaryServiceImpl implements ZbksAttackSummaryService {
	private static final Gson GSON = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();

	@Autowired
	private ProvinceMapper provinceMapper;

	@Autowired
	private IndustryMapper industryMapper;

	@Autowired
	private CustomerMapper customerMapper;

	@Autowired
	private DeviceMapper deviceMapper;

	@Override
	public String getProvinceAndInDustroy() {
		Map<String, Object> map = new HashMap<String, Object>();
		List<Province> provinces = provinceMapper.select(null);
		List<Industry> industrys = industryMapper.select(null);
		map.put("province", provinces);
		map.put("industry", industrys);
		return JSonUtil.object2JSon(map);
	}

	@Override
	public String getDevices() {
		List<Device> devices = deviceMapper.select(null);
		return JSonUtil.object2JSon(devices);
	}

	@Override
	public String queryCustomerSattackByProvinceAndIndustry(Integer pageNum, Integer pageSize, String start, String end, String provinces, String industrys,String groupBy) {
		PageHelper.startPage(pageNum, pageSize);
		List<Map<String, Object>> cs = customerMapper.queryCustomerSattackByProvinceAndIndustry(start, end, StringUtil.string2List(provinces, ";"), StringUtil.string2List(industrys, ";"),groupBy);
		// 用PageInfo对结果进行包装
		PageInfo page = new PageInfo(cs);
		return JSonUtil.object2JSon(page);
	}

	@Override
	public String getattackTrend(String begin, String end, String province, String industry) {
		List<Map<String, Object>> cs = deviceMapper.attackTrend(begin, end, province, industry);
		return JSonUtil.object2JSon(cs);
	}

	@Override
	public String getAttackSourceRanking(Integer pageNum, Integer pageSize, String begin, String end, String province, String industry) {
		PageHelper.startPage(pageNum, pageSize);
		List<Map<String, Object>> ls = deviceMapper.attackSourceRanking(begin, end, province, industry);
		// 用PageInfo对结果进行包装
		PageInfo page = new PageInfo(ls);
		return JSonUtil.object2JSon(page);
	}

	@Override
	public String getAttackDetails(String begin, String end, String type, String customers) {
		List<Map<String, Object>> ls = customerMapper.attackDetails(begin, end, type, StringUtil.string2List(customers, ";"));
		return JSonUtil.object2JSon(ls);
	}

}
